package com.atguigu.lease.common.sms;



import com.aliyun.teaopenapi.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(AliyunSMSproperties.class)
@ConditionalOnProperty(prefix = "aliyun.sms", name = "endpoint")
public class AliyunSmsConfiguration {
    @Autowired
    private AliyunSMSproperties aliyunSMSproperties;

    @Bean
    public Client createClient(){
        Config config = new Config();
        config.setAccessKeyId(aliyunSMSproperties.getAccessKeyId());
        config.setAccessKeySecret(aliyunSMSproperties.getAccessKeySecret());
        config.setEndpoint(aliyunSMSproperties.getEndpoint());
        try {
            return new Client(config);
        }catch (Exception e){
            throw  new RuntimeException(e);
        }
    }
}
